package com.zhy.http.okhttp.request;

import java.io.IOException;
import okhttp3.MediaType;
import okhttp3.RequestBody;
import okio.Buffer;
import okio.BufferedSink;
import okio.ForwardingSink;
import okio.Okio;
import okio.Sink;

public class CountingRequestBody extends RequestBody
{
  protected CountingSink countingSink;
  protected RequestBody delegate;
  protected Listener listener;

  public CountingRequestBody(RequestBody paramRequestBody, Listener paramListener)
  {
    this.delegate = paramRequestBody;
    this.listener = paramListener;
  }

  public long contentLength()
  {
    try
    {
      long l = this.delegate.contentLength();
      return l;
    }
    catch (IOException localIOException)
    {
      localIOException.printStackTrace();
    }
    return -1L;
  }

  public MediaType contentType()
  {
    return this.delegate.contentType();
  }

  public void writeTo(BufferedSink paramBufferedSink)
    throws IOException
  {
    this.countingSink = new CountingSink(paramBufferedSink);
    BufferedSink localBufferedSink = Okio.buffer(this.countingSink);
    this.delegate.writeTo(localBufferedSink);
    localBufferedSink.flush();
  }

  protected final class CountingSink extends ForwardingSink
  {
    private long bytesWritten = 0L;

    public CountingSink(Sink arg2)
    {
      super();
    }

    public void write(Buffer paramBuffer, long paramLong)
      throws IOException
    {
      super.write(paramBuffer, paramLong);
      this.bytesWritten = (paramLong + this.bytesWritten);
      CountingRequestBody.this.listener.onRequestProgress(this.bytesWritten, CountingRequestBody.this.contentLength());
    }
  }

  public static abstract interface Listener
  {
    public abstract void onRequestProgress(long paramLong1, long paramLong2);
  }
}

/* Location:           C:\Users\user\Desktop\dd28_pcdd720\classes_dex2jar.jar
 * Qualified Name:     com.zhy.http.okhttp.request.CountingRequestBody
 * JD-Core Version:    0.6.2
 */